package com.jy.adscm.security.browser.authentication;

import com.jy.adscm.security.properties.SecurityConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

/**
 * @author yyy
 * @ClassName FormAuthenticationConfig
 * @Description 表单登录配置
 * @date 2018/7/26 15:28
 */
@Component
public class FormAuthenticationConfig {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    protected AuthenticationSuccessHandler formAdscmAuthenticationSuccessHandler;

    @Autowired
    protected AuthenticationFailureHandler formAdscmAuthenticationFailureHandler;

    public void configure(HttpSecurity http) throws Exception {

        logger.info("进入表单登录配置...");
        http.formLogin()
                .loginPage(SecurityConstants.DEFAULT_UNAUTHENTICATION_URL)//默认登录页面
                .loginProcessingUrl(SecurityConstants.DEFAULT_SIGN_IN_PROCESSING_URL_FORM)//默认的用户名密码登录请求处理url
                .successHandler(formAdscmAuthenticationSuccessHandler)//登录成功处理逻辑
                .failureHandler(formAdscmAuthenticationFailureHandler);//登录失败处理逻辑
    }
}
